package com.iseastar.guojiang.dialog;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.InputFilter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.amap.api.location.DPoint;
import com.iseastar.BaseActivity2;
import com.iseastar.dianxiaosan.home.parcel.ParcelCheckActivity;
import com.iseastar.guojiang.app.AppCache;
import com.iseastar.guojiang.app.Intents;
import com.iseastar.guojiang.consts.MsgID;
import com.iseastar.guojiang.logic.AppHttp;
import com.iseastar.guojiang.logic.AppLogic;
import com.iseastar.guojiang.mine.SettingFragment;
import com.iseastar.guojiang.model.NewParcelBean;
import com.iseastar.guojiang.model.OrderBean;
import com.iseastar.guojiang.model.ServiceTaskBean;
import com.iseastar.guojiang.model.UserBean;
import com.iseastar.guojiang.newcabinet.ParcelListActivity;
import com.iseastar.guojiang.newcabinet.SameCityTaskMainActivity;
import com.iseastar.guojiang.newcabinet.SameCityTaskStageFragment;
import com.iseastar.guojiang.newcabinet.TaskMainDetailActivity;
import com.iseastar.guojiang.newcabinet.TaskStageFragment;
import com.iseastar.guojiang.register.RegisterCourierStepActivity;
import com.iseastar.guojiang.team.CourierTeamCenterDetailActivity;
import com.iseastar.guojiang.team.CreateCourierTeamActivity;
import com.iseastar.guojiang.team.TeamCenterZoneListActivity;
import com.iseastar.guojiang.transfer.ParcelHandoverDetailsListActivity;
import com.iseastar.guojiang.transfer.ParcelTransferListActivity;
import com.iseastar.guojiang.transfer.TaskSatelliteWarehouseActivity;
import com.iseastar.guojiang.util.LocationUtils;
import com.iseastar.guojiang.view.DeleteEditText;
import com.iseastar.guojiang.view.TimePicker;
import com.iseastar.guojiang.wallet.CourierBindWXActivity;
import com.shouhuobao.station.R;
import com.shouhuobao.take.mine.TakeWhetherChargesActivity;
import com.shouhuobao.take.model.ParcelBean;
import com.shouhuobao.take.utils.DateUtils;
import com.shouhuobao.take.utils.StringUtils;
import com.shouhuobao.take.weight.CircularImage;

import java.util.ArrayList;
import java.util.List;

import droid.frame.activity.HandlerMgr;
import droid.frame.app.Callback;
import droid.frame.ui.dialog.AppDialog;
import droid.frame.ui.dialog.BaseDialog;
import droid.frame.utils.Android;
import droid.frame.utils.GlideUtil;
import droid.frame.utils.android.Log;
import droid.frame.utils.lang.Str;
import droid.frame.view.CodeLinearLayout;
import droid.frame.view.InputFilterExt;
import droid.frame.view.TextWatcherExt;
import droid.frame.view.ViewPagerExt;

import static droid.frame.App.getHandler;

/**
 * 项目中所有的对话框显示都在此类中管理
 *
 * @author coffee<br>
 * 2015-4-8下午4:36:46
 */
@SuppressLint("ResourceAsColor")
public class DialogMgr {

    /**
     * xmpp推送用户取消订单的消息<br>
     * <p>
     * 用户订单取消提示
     */
    public static void showOrderCancelTip(final Activity context, final int orderId) {
        getHandler().post(new Runnable() {
            @Override
            public void run() {
                final AppDialog dialog = new AppDialog(context, false);
                dialog.setTitle("订单取消").setContent("用户已取消了此订单, 开始接新订单吧~");
                dialog.setConfirmClickListener("知道了", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.cancel();
                        HandlerMgr.sendMessage(MsgID.xmpp_order_details_cancel, null);
                    }
                });
                dialog.setCancelable(false);
                dialog.show();
            }
        });
    }

    /**
     * 报价
     *
     * @param context
     * @param userId
     * @param order
     */
    public static void showQuoteDialog(final Activity context, final int userId, final OrderBean order) {
        final AppDialog dialog = new AppDialog(context);
        dialog.setContent("报价后将无法返回, 请向用户核对用户填写信息, 确保信息完全正确", Gravity.LEFT);
        dialog.setCancelClickListener("取消", null);
        dialog.setConfirmClickListener("确认", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppHttp.getInstance().orderQuotePrice(order);
                dialog.cancel();
            }
        });
        dialog.setCancelable(false);
        dialog.show();
        // dialog.superShow();
    }

    /**
     * 显示订单支付成功
     */
    public static void showOrderPayOk(final Activity context, final String name, final String price, final View.OnClickListener clickListener) {
        getHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Activity activity = context;
                final AppDialog dialog = new AppDialog(activity, false);
                String format = "%s已经成功支付%s元, 开始接新订单吧~";
                String payOk;
                if (name == null || name.equals("null")) {
                    payOk = String.format(format, "", price);
                } else {
                    payOk = String.format(format, name, price);
                }
                dialog.setTitle("").setContent(payOk);
                dialog.setConfirmClickListener("继续接单", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.cancel();
                        clickListener.onClick(v);
                    }
                });
                dialog.setCancelable(true);
                dialog.show();
            }
        }, 0);
    }

    /**
     * 店小三 弹窗 我的二维码
     */

    public static BaseDialog showMyCode(final Activity context, UserBean station) {
        final BaseDialog dialog = new BaseDialog((Activity) context);
        dialog.setContentView(R.layout.my_code);
        TextView name = (TextView) dialog.findViewById(R.id.store_name);
        name.setText(station.getName());// 驿站名称
        TextView code = (TextView) dialog.findViewById(R.id.store_post_code);
        code.setText("驿站编号: " + station.getCode());// 驿站编号
        ImageView photo = (ImageView) dialog.findViewById(R.id.store_photo);

        AppLogic.loadImage(station.getQrCodeUrl(), photo);

        ImageView close = (ImageView) dialog.findViewById(R.id.store_code_close);
        close.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 店小三 拨打电话弹出的对话框：客服
     *
     * @param context
     * @param serviceTime 服务时间
     * @author huxindan
     */
    public static void showPhoneDialog(final Activity context, String serviceTime) {
        final AppDialog dialog = new AppDialog(context);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("呼叫 400-617-1949");
        if (serviceTime == null) {
            dialog.setContent(context.getResources().getString(R.string.service_phone));
        } else {
            dialog.setContent(serviceTime);
        }
        dialog.setConfirmClickListener("呼叫", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:400-617-1949"));
                context.startActivity(intent);
            }
        });
        dialog.setCancelClickListener("取消", null);
        dialog.show();
    }

    /**
     * 店小三 拨打电话弹出的对话框：客服
     *
     * @param context 服务时间
     * @author huxindan
     */
    public static void showPauseDialog(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("如果你要暂停营业");
        dialog.setContent("请联系客服处理");
        dialog.setConfirmClickListener("拨号", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:400-617-1949"));
                context.startActivity(intent);
            }
        });
        dialog.setCancelClickListener("取消", null);
        dialog.show();
    }

    /**
     * 在核对包裹信息时弹出的提示
     *
     * @param context
     */
    public static void showPrcelCheck(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("确定收取包裹?");
        dialog.setCancelClickListener("取消", null);
        dialog.setConfirmClickListener("确定", new OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    public static AppDialog showQuit(final Activity context, final Callback callback) {
        final AppDialog dialog = new AppDialog(context, false);
        // dialog.setCanceledOnTouchOutside(false);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("是否退出登录？");
        dialog.setConfirmClickListener("取消", null);
        dialog.setCancelClickListener("确定", new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 退出登录
                try {
                    AppCache.setUser(null);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
                if (callback != null) {
                    callback.onDialogDismiss();
                }
            }
        });
        dialog.show();
        return dialog;
    }

    public static AppDialog showActiveTips(final Activity context, final Callback callback) {
        final AppDialog dialog = new AppDialog(context, false);
        // dialog.setCanceledOnTouchOutside(false);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("上周榜单已经发出啦，快看有没有中奖!");
        dialog.setConfirmClickListener("取消", null);
        dialog.setCancelClickListener("前往", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (callback != null) {
                    callback.onDialogDismiss();
                }
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 新版本不需要更新提示
     *
     * @param context
     * @return
     */
    public static AppDialog showNoUpdate(final Activity context) {
        final AppDialog dialog = new AppDialog(context, false);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("已经是最新版本,不需要更新！");
        dialog.setCancelClickListener("知道了", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 暂停提示
     *
     * @param context
     * @return
     */
    public static AppDialog showStationPause(final Activity context) {
        final AppDialog dialog = new AppDialog(context, false);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("您的店已暂停营业");
        dialog.setContent("无法使用这个功能");
        dialog.setCancelClickListener("知道了", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 店小三 寄件码弹窗
     *
     * @param context
     * @return
     */
    public static BaseDialog showParcelCode(final Activity context) {
        final BaseDialog dialog = new BaseDialog((Activity) context);
        dialog.setContentView(R.layout.parcel_check_code);
        final EditText mParcelCode = (EditText) dialog.findViewById(R.id.parcel_check_code);
        ImageView close = (ImageView) dialog.findViewById(R.id.parcel_code_close);
        close.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        mParcelCode.addTextChangedListener(new TextWatcherExt() {
            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() == 6) {
                    String mCode = mParcelCode.getText().toString();
                    Intent intent = new Intent(context, ParcelCheckActivity.class);
                    intent.putExtra("code", mCode);
                    intent.putExtra("type", 1);
                    context.startActivity(intent);
                    dialog.dismiss();
                }
            }
        });
        dialog.show();
        getHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Android.showSoftInput(context, mParcelCode);
            }
        }, 250);
        return dialog;
    }

    /**
     * 密码取货验证界面
     */
    public static BaseDialog showTakeAwayByCode(final Activity context, final ParcelBean parcel) {
        final BaseDialog dialog = new BaseDialog((Activity) context);
        dialog.setContentView(R.layout.take_parcel_away_bycode);
        TextView receiverPhone = (TextView) dialog.findViewById(R.id.take_receiver_phone);
        TextView receiverName = (TextView) dialog.findViewById(R.id.take_receiver_name);
        receiverPhone.setText(parcel.getReceiverPhone());
        receiverName.setText(parcel.getReceiverName());
        //
        final CodeLinearLayout mCodeLayout = (CodeLinearLayout) dialog.findViewById(R.id.take_parcel_checkcode_layout);
        mCodeLayout.setCallback(new Callback() {
            @Override
            public void execute(Object... result) {
                AppHttp.getInstance().takeParcelByCode(parcel.getId(), mCodeLayout.getText());
            }
        });

        ImageView close = (ImageView) dialog.findViewById(R.id.parcel_code_close);
        close.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        getHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Android.showSoftInput(context, mCodeLayout.getChildAt(0));
            }
        }, 250);
        return dialog;
    }


    /**
     * app通用的信息显示框
     */
    public static AppDialog showAppMessage(final Activity context, String message) {
        AppDialog dialog = new AppDialog(context);
        dialog.setContent(message);
        dialog.setConfirmClickListener("我知道了", null);
        dialog.show();
        return dialog;
    }

    public static PopupWindow createPopupWindow(final Activity context, View layout) {
        PopupWindow mpWindow = new PopupWindow(layout, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        mpWindow.setOutsideTouchable(true);// popupwindow设置触摸可消失
        // ColorDrawable dw = new ColorDrawable(android.R.color.black);
        // dw.setAlpha(180);
        // mpWindow.setBackgroundDrawable(dw); // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        // popupwindow显示方式
        // mpWindow.showAtLocation(context.findViewById(R.id.address_call), Gravity.RIGHT | Gravity.BOTTOM, 0, 0);
        mpWindow.setFocusable(true);// 这里必须设置为true才能点击区域外或者消失
        mpWindow.setTouchable(true);// 这个控制PopupWindow内部控件的点击事件
        mpWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mpWindow.setOutsideTouchable(true);
        mpWindow.setAnimationStyle(R.style.popup_window_bottom2top);
        mpWindow.update();
        // 设置背景变暗
        final Window window = context.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.alpha = 0.7f;
        window.setAttributes(lp);
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        // context.findViewById(android.R.id.content).setAlpha(0.7F);
        mpWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                resetWindowAttribute(context);
            }
        });
        return mpWindow;
    }

    private static void resetWindowAttribute(Activity context) {
        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = 1f;
        context.getWindow().setAttributes(lp);
        context.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    /**
     * 点击我的头像查看图片
     */
    @SuppressLint("WrongConstant")
    public static BaseDialog showStorePhoto(Activity context, String imageUrl, OnClickListener onClickListener) {
        final BaseDialog dialog = new BaseDialog(context);
        dialog.setContentView(R.layout.layout_take_store_photo);
        //点击关闭popWindow
        View closeV = dialog.findViewById(R.id.close_iv);
        View updatePhotoV = dialog.findViewById(R.id.update_photo_bt);
        closeV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //点击更换头像
        updatePhotoV.setOnClickListener(onClickListener);
        if (!StringUtils.isEmpty(imageUrl)) {
            GlideUtil.loadImage(context, imageUrl, 0, (ImageView) dialog.findViewById(R.id.store_photo_iv));
        } else {
            ((ImageView) dialog.findViewById(R.id.store_photo_iv)).setImageResource(R.drawable.take_default_store_photo);
        }
        dialog.show();
        return dialog;
    }

    /**
     * 点击我的头像查看图片
     */
    @SuppressLint("WrongConstant")
    public static BaseDialog showLargeStationPhoto(Activity context, String imageUrl) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.dialog_station_large_photo);
        if (!StringUtils.isEmpty(imageUrl)) {
            GlideUtil.loadImage(context, imageUrl, 0, (ImageView) dialog.findViewById(R.id.large_photo_iv));
        } else {
            ((ImageView) dialog.findViewById(R.id.large_photo_iv)).setImageResource(R.drawable.take_default_store_photo);
        }
        dialog.findViewById(R.id.cancel_iv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 点击选择地图导航
     */
    @SuppressLint("WrongConstant")
    public static void showSelectMapToNavigation(Activity context, View parent, final double bdlat, final double bdlng, final double gdlat, final double gdlng) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_select_map_navigation, null);
        final PopupWindow popupWindow = createPopupWindow(context, view);
        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        if (bdlat > 0 && bdlng > 0) {
            //百度地图导航
            view.findViewById(R.id.bd_map_tv).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intents.navigation(bdlat, bdlng, gdlat, gdlng, 0);
                    popupWindow.dismiss();
                }
            });
        }
        final DPoint dPoint = LocationUtils.convertToGaoDeLocation(bdlat, bdlng);
        if (dPoint != null) {
            Log.d("33333", "坐标转换：" + dPoint.getLatitude() + "," + dPoint.getLongitude());
            //高德地图导航
            view.findViewById(R.id.gd_map_tv).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intents.navigation(bdlat, bdlng, dPoint.getLatitude(), dPoint.getLongitude(), 1);
                    popupWindow.dismiss();
                }
            });
        }
        //取消导航
        view.findViewById(R.id.cancel_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
    }

    /**
     * 解绑火箭侠微信账号提示框
     */
    public static BaseDialog showUnBindWXTips(final Activity context) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.layout_courier_unbind_wx);
        //取消
        dialog.findViewById(R.id.cancel_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //解除微信绑定
        dialog.findViewById(R.id.unbind_wx_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((CourierBindWXActivity) context).unBindWX();
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 火箭侠选择交接时间
     */
    @SuppressLint("WrongConstant")
    public static void courierSelectTransferTime(final BaseActivity2 context, View parent, final String time) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_courier_transfer_select_time, null);
        final PopupWindow popupWindow = createPopupWindow(context, view);
        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        final TimePicker startTP = (TimePicker) view.findViewById(R.id.selectStartTP);
        TimePicker endTP = (TimePicker) view.findViewById(R.id.selectEndTP);
        final String[] timeStr = new String[2];
        if (StringUtils.isEmpty(time) || !time.contains("-")) {
            startTP.setCurrentHour("00");
            startTP.setCurrentMinute("00");
            endTP.setCurrentHour("00");
            endTP.setCurrentMinute("00");
        } else {
            String startTime = time.split("-")[0];
            String endTime = time.split("-")[1];
            startTP.setCurrentHour(startTime.split(":")[0]);
            startTP.setCurrentMinute(startTime.split(":")[1]);
            endTP.setCurrentHour(endTime.split(":")[0]);
            endTP.setCurrentMinute(endTime.split(":")[1]);
        }
        //选择交接的开始的时间
        startTP.setOnDateChangedListener(new TimePicker.OnDateChangedListener() {

            @Override
            public void onDateChanged(TimePicker view, String hour, String minute) {
                timeStr[0] = hour + ":" + minute;
            }
        });
        //选择交接的结束时间
        endTP.setOnDateChangedListener(new TimePicker.OnDateChangedListener() {

            @Override
            public void onDateChanged(TimePicker view, String hour, String minute) {
                timeStr[1] = hour + ":" + minute;
            }
        });
        //选择完成时间
        view.findViewById(R.id.finish_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if (!StringUtils.isEmpty(time) && time.contains("-")) {
                        //打开时间选择器，没有进行重新选择时间
                        if (StringUtils.isEmpty(timeStr[0]) && StringUtils.isEmpty(timeStr[1])) {
                            popupWindow.dismiss();
                        } else {
                            String startTime = timeStr[0];
                            String endTime = timeStr[1];
                            //判断选择的结束时间要大于开始时间
                            if (StringUtils.isEmpty(startTime)) {
                                startTime = time.split("-")[0];
                            }
                            if (StringUtils.isEmpty(endTime)) {
                                endTime = time.split("-")[1];
                            }
                            if (DateUtils.getTimeHHmmFormat().parse(endTime).getTime() > DateUtils.getTimeHHmmFormat().parse(startTime).getTime()) {
                                ((TaskSatelliteWarehouseActivity) context).finishSelectTime(startTime + "-" + endTime);
                                popupWindow.dismiss();
                            } else {
                                context.showToast("交接结束时间需要大于交接开始时间");
                            }
                        }
                    } else {
                        if (StringUtils.isEmpty(timeStr[0]) || StringUtils.isEmpty(timeStr[1])) {
                            context.showToast("请选择交接时间");
                        } else {
                            if (DateUtils.getTimeHHmmFormat().parse(timeStr[1]).getTime() > DateUtils.getTimeHHmmFormat().parse(timeStr[0]).getTime()) {
                                ((TaskSatelliteWarehouseActivity) context).finishSelectTime(timeStr[0] + "-" + timeStr[1]);
                                popupWindow.dismiss();
                            } else {
                                context.showToast("交接结束时间需要大于交接开始时间");
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 火箭侠卫星仓包裹交接
     */
    @SuppressLint("WrongConstant")
    public static void parcelHandoverDetailListPopw(final Activity context, View parent, final int position, NewParcelBean bean) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_parcel_handover_details_popw, null);
        final PopupWindow popupWindow = createPopupWindow(context, view);
        //完整
        TextView completeTV = (TextView) view.findViewById(R.id.complete_tv);
        //破损
        TextView breakageTV = (TextView) view.findViewById(R.id.breakage_tv);
        //缺失
        TextView missingTV = (TextView) view.findViewById(R.id.missing_tv);
        //其他
        TextView otherTV = (TextView) view.findViewById(R.id.other_tv);
        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        initParcelHandoverDetailListPopw(bean, completeTV, breakageTV, missingTV, otherTV);
        //取消
        view.findViewById(R.id.cancel_btn).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        //完整
        completeTV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelHandoverDetailsListActivity) context).refreshParcelStatus(1, position);
                popupWindow.dismiss();
            }
        });
        //破损
        breakageTV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelHandoverDetailsListActivity) context).refreshParcelStatus(2, position);
                popupWindow.dismiss();
            }
        });
        //缺失
        missingTV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelHandoverDetailsListActivity) context).refreshParcelStatus(3, position);
                popupWindow.dismiss();
            }
        });
        //其他
        otherTV.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelHandoverDetailsListActivity) context).refreshParcelStatus(4, position);
                popupWindow.dismiss();
            }
        });
    }

    /**
     * 初始化火箭侠交接详情修改状态选择的背景和颜色字体
     *
     * @param bean
     * @param textViews
     */
    private static void initParcelHandoverDetailListPopw(NewParcelBean bean, TextView... textViews) {
        if (bean == null) {
            textViews[0].setBackgroundResource(R.drawable.task_app_button_press_shape);
            textViews[0].setTextColor(R.color.white);
            textViews[1].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
            textViews[1].setTextColor(R.color.courier_color_999999);
            textViews[2].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
            textViews[2].setTextColor(R.color.courier_color_999999);
            textViews[3].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
            textViews[3].setTextColor(R.color.courier_color_999999);
        } else {
            //破损
            if (bean.getParcelStatus() == 2) {
                textViews[0].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[0].setTextColor(R.color.courier_color_999999);
                textViews[1].setBackgroundResource(R.drawable.task_app_button_press_shape);
                textViews[1].setTextColor(R.color.white);
                textViews[2].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[2].setTextColor(R.color.courier_color_999999);
                textViews[3].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[3].setTextColor(R.color.courier_color_999999);
            }
            //丢失
            else if (bean.getParcelStatus() == 3) {
                textViews[0].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[0].setTextColor(R.color.courier_color_999999);
                textViews[1].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[1].setTextColor(R.color.courier_color_999999);
                textViews[2].setBackgroundResource(R.drawable.task_app_button_press_shape);
                textViews[2].setTextColor(R.color.white);
                textViews[3].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[3].setTextColor(R.color.courier_color_999999);
            }
            //其他
            else if (bean.getParcelStatus() == 4) {
                textViews[0].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[0].setTextColor(R.color.courier_color_999999);
                textViews[1].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[1].setTextColor(R.color.courier_color_999999);
                textViews[2].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[2].setTextColor(R.color.courier_color_999999);
                textViews[3].setBackgroundResource(R.drawable.task_app_button_press_shape);
                textViews[3].setTextColor(R.color.white);
            }
            //正常
            else {
                textViews[0].setBackgroundResource(R.drawable.task_app_button_press_shape);
                textViews[0].setTextColor(R.color.white);
                textViews[1].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[1].setTextColor(R.color.courier_color_999999);
                textViews[2].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[2].setTextColor(R.color.courier_color_999999);
                textViews[3].setBackgroundResource(R.drawable.task_contact_sender_phone_d7d7d7_bg);
                textViews[3].setTextColor(R.color.courier_color_999999);
            }
        }
    }

    /**
     * 火箭侠卫星仓交件入仓
     *
     * @param context
     */
    public static void showHandoverWarehouse(final Activity context, final ArrayList<NewParcelBean> items) {
        final AppDialog dialog = new AppDialog(context);
        TextView dialogOK = (TextView) dialog.findViewById(R.id.app_dialog_cancel);
        dialogOK.setTextColor(context.getResources().getColor(R.color.app_theme_color2));
        dialog.setTitle("揽收确认");
        dialog.setContent("确定交接该" + items.size() + "个包裹？");
        dialog.setCancelClickListener("取消", null);
        dialog.setConfirmClickListener("确定", new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelHandoverDetailsListActivity) context).handoverWarehous();
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 设置默认仓提示框
     */
    public static BaseDialog setDefaultTransferDialog(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextColor(context.getResources().getColor(R.color.black_100));
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextSize(20);
        dialog.setContent("确认设置该交接点为默认交接点？");
        dialog.setConfirmClickListener("确定", new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelTransferListActivity) context).setDefaultTransfer();
                dialog.dismiss();
            }
        });
        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 代收包裹自定义收费标注
     *
     * @param context
     * @param type    1 小包  2 大包
     * @return
     */
    public static BaseDialog showTakeSetPayMoney(final BaseActivity2 context, final int type, final double maxMoney) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.layout_take_setpay_money);
        final EditText mMoneyET = (EditText) dialog.findViewById(R.id.money_ET);
        ((TextView) dialog.findViewById(R.id.max_money_tv)).setText("（最高" + maxMoney + "元）");
        //输入金额确认
        dialog.findViewById(R.id.take_submit_TV).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StringUtils.isEmpty(mMoneyET.getText().toString())) {
                    ((TakeWhetherChargesActivity) context).setSmallOrBigPrice(0, type);
                    dialog.dismiss();
                } else {
                    String money = mMoneyET.getText().toString();
                    if (!StringUtils.isNumber(money)) {
                        context.showToast("输入的金额有误");
                        return;
                    }
                    if (Double.parseDouble(mMoneyET.getText().toString()) > maxMoney) {
                        if (type == 1) {
                            context.showToast("最多可输入" + maxMoney + "元");
                        } else if (type == 2) {
                            context.showToast("最多可输入" + maxMoney + "元");
                        }
                        return;
                    } else {
                        ((TakeWhetherChargesActivity) context).setSmallOrBigPrice(Double.parseDouble(mMoneyET.getText().toString()), type);
                        dialog.dismiss();
                    }
                }
            }
        });
        mMoneyET.addTextChangedListener(new TextWatcherExt() {
            @Override
            public void afterTextChanged(Editable s) {
                if (!StringUtils.isEmpty(s.toString())) {
                    if (StringUtils.isNumber(s.toString())) {
                        if (Double.parseDouble(s.toString()) > maxMoney) {
                            if (type == 1) {
                                context.showToast("最多可输入" + maxMoney + "元");
                            } else if (type == 2) {
                                context.showToast("最多可输入" + maxMoney + "元");
                            }
                        }
                    } else {
                        context.showToast("输入的金额有误");
                    }
                }
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 提示当月不能再次设置收费标注
     */
    public static BaseDialog showNotSubmitCostDialog(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextColor(context.getResources().getColor(R.color.black_100));
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextSize(18);
        dialog.setContent("您本月已修改过1次信息，不能重复修改");
        dialog.setConfirmClickListener("确定", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 火箭联盟第一次设置收费提示
     */
    public static BaseDialog showFirstSetCostDialog(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextColor(context.getResources().getColor(R.color.black_100));
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextSize(18);
        dialog.setContent("待收货收费功能即将上线，提前设置收费方案，抢赚第一笔代收收益。");
        dialog.setConfirmClickListener("确定", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return dialog;
    }

    /**
     * 火箭联盟切换火箭侠
     */
    public static void switchCourier(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextColor(context.getResources().getColor(R.color.black_100));
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextSize(15);
        dialog.setTitle("您还不是火箭侠");
        dialog.setContent("火箭侠正在火热招募中，月赚上万不是梦，详情咨询4006171949");
        dialog.setConfirmClickListener("咨询客服", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Intents.dialOrCall("400-617-1949");
            }
        });
        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 火箭侠切换火箭联盟
     */
    public static void switchTake(final SettingFragment context) {
        final AppDialog dialog = new AppDialog(context.getActivityContext());
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextColor(context.getResources().getColor(R.color.black_100));
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextSize(18);
        dialog.setTitle("您还未开通火箭驿站");
        dialog.setConfirmClickListener("申请开通", new OnClickListener() {
            @Override
            public void onClick(View v) {
                context.switchToAvenger();
                dialog.dismiss();
            }
        });
        dialog.setCancelClickListener("返回火箭侠", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 联系收件人/联系寄件人
     *
     * @param type 1 联系同城的寄件 2  联系同城的收件 3 上门的寄件
     */
    public static void receiverOrSendCall(Activity context, final String phone, int type, String address, String contactName) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.layout_receiver_or_send_call_dialog);
        TextView contentTV = (TextView) dialog.findViewById(R.id.content_tv);
        Button callBtn = (Button) dialog.findViewById(R.id.call_btn);
        UserBean userBean = AppCache.getUser();
        if (type == 1) {
            contentTV.setText("您好，我是火箭投递火箭侠" + userBean.getNickName() + "，您选择了火箭投递同城直送服务，我将在x分钟内到达，电话与您再确认一下地址是" + address + "吗？");
            callBtn.setText("联系寄件人");
        } else if (type == 2) {
            contentTV.setText("您好，我是火箭投递火箭侠" + userBean.getNickName() + "，您的朋友" + contactName + "给您邮寄了物品，我预计还有x分钟到达，再和您确认一下地址是" + address + "吗？");
            callBtn.setText("联系收件人");
        } else if (type == 3) {
            contentTV.setText("您好，我是火箭投递火箭侠" + userBean.getNickName() + "，您选择了火箭投递寄件上门服务，我将在x分钟内到达，电话与您再确认一下地址是" + address + "吗？");
            callBtn.setText("联系寄件人");
            callBtn.setBackgroundResource(R.drawable.same_city_receiver_or_send_button_6783d8_bg);
            //            callBtn.setPadding(130, 30, 130, 30);
        }
        callBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intents.dialOrCall(phone);
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 不需要收件码时任务阶段弟四阶段的确认已送达
     */
    public static void affirmArrived(final SameCityTaskStageFragment context) {
        final AppDialog dialog = new AppDialog(context.getActivityContext());
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextColor(context.getResources().getColor(R.color.app_font_2));
        ((TextView) dialog.findViewById(R.id.app_dialog_content)).setTextSize(16);
        ((TextView) dialog.findViewById(R.id.app_dialog_title)).setTextColor(context.getResources().getColor(R.color.app_font));
        ((TextView) dialog.findViewById(R.id.app_dialog_title)).setTextSize(20);
        dialog.setTitle("重要提示");
        dialog.setContent("请在收件人签收后在点击确认已送达，如有提前点击、未送货给收件人等行为发生，我们将扣除本单收入，并按照相关协议罚款，涉案较大的移送公安机关处理！");
        dialog.setConfirmClickListener("确认已送达", new OnClickListener() {
            @Override
            public void onClick(View v) {
                context.affirmArrivedData();
                dialog.dismiss();
            }
        });
        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 火箭侠注册物料图片展示
     *
     * @param context
     */
    private static int imageCurrentPosition = 0;//当前点击图片的位置

    public static void registerPhotoViewPager(Activity context, final ArrayList<String> items) {
        imageCurrentPosition = 0;
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.layout_register_material_photo);
        ViewPagerExt mViewPager = (ViewPagerExt) dialog.findViewById(R.id.register_view_pager);
        final TextView mRegisterNumTV = (TextView) dialog.findViewById(R.id.register_num_tv);
        ImageView mRegisterSubmitIcon = (ImageView) dialog.findViewById(R.id.register_submit_icon);
        List<View> pager = new ArrayList<View>();
        for (int i = 0; i < items.size(); i++) {
            ImageView parms = new ImageView(context);
            parms.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
            GlideUtil.loadImage(context, items.get(i), 0, parms);
            pager.add(parms);
        }
        mViewPager.setViewItems(pager, false);
        mViewPager.setCurrentItem(imageCurrentPosition);
        mRegisterNumTV.setText((imageCurrentPosition + 1) + "/" + items.size());
        mRegisterSubmitIcon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                imageCurrentPosition = position;
                mRegisterNumTV.setText((position + 1) + "/" + items.size());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        dialog.show();
    }

    /**
     * 火箭侠登录成功未注册弹窗
     */
    public static void courierLoginDialog(final Activity context, final UserBean item) {
        final AppDialog dialog = new AppDialog(context);
        TextView content = (TextView) dialog.findViewById(R.id.app_dialog_content);
        content.setTextSize(16);
        dialog.setContent("您还不是火箭侠哦，立即加入火箭侠，月入上万不是梦！");
        dialog.setConfirmClickListener("立即申请加入", new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, RegisterCourierStepActivity.class);
                intent.putExtra("item", item);
                context.startActivity(intent);
                context.setResult(Activity.RESULT_OK);
                context.finish();
                dialog.dismiss();
            }
        });
        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 上门驿站显示
     *
     * @param context
     */
    public static void stationShow(Activity context, ServiceTaskBean serviceTaskBean) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.layout_station_show);
        ImageView mStationImage = dialog.findViewById(R.id.station_image);
        TextView mStationTitle = dialog.findViewById(R.id.station_title);
        TextView mStationAddress = dialog.findViewById(R.id.station_address);
        mStationTitle.setText(serviceTaskBean.getStationName());
        GlideUtil.loadImage(context, serviceTaskBean.getStationHeadImg(), R.drawable.station_icon, mStationImage);
        mStationAddress.setText(serviceTaskBean.getStationAddress());
        dialog.findViewById(R.id.know).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }

    //实名
    @SuppressLint("WrongConstant")
    public static void realPopupWindow(final Activity context, View parent, NewParcelBean parcelBean) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_real_popw, null);
        final PopupWindow popupWindow = createPopupWindow(context, view);
        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        //取消
        view.findViewById(R.id.cancel_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        //扫描身份证
        view.findViewById(R.id.capacity_real_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelListActivity) context).setIdCardInfo(0);
                popupWindow.dismiss();
            }
        });
        //手动身份信息录入
        view.findViewById(R.id.entering_real_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ParcelListActivity) context).setIdCardInfo(1);
                popupWindow.dismiss();
            }
        });
    }

    /**
     * 火箭侠组队前规则提示
     *
     * @param context
     */
    public static void createATeamRuleDialog(final Activity context) {
        final AppDialog dialog = new AppDialog(context);
        TextView titleTV = (TextView) dialog.findViewById(R.id.app_dialog_title);
        titleTV.setText("温馨提示");
        titleTV.setGravity(Gravity.LEFT);
        titleTV.setTextSize(20);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.getPaint().setFakeBoldText(true);
        TextView contentTV = (TextView) dialog.findViewById(R.id.app_dialog_content);
        contentTV.setGravity(Gravity.LEFT);
        contentTV.setTextSize(16);
        contentTV.setVisibility(View.VISIBLE);
        contentTV.setTextColor(R.color.app_font_2);
        contentTV.setLineSpacing(3, 1.2f);
        contentTV.setText("1. 创建战队后10天内需要加入战队5个人即可开通成功；\n" +
                "2. 10天后若不足5人，战队自动解散；\n" +
                "3. 10天内您可以随时解散战队；\n" +
                "4. 10天后若战队成功开通，需保持至少2个月不得解散；");
        dialog.setConfirmClickListener("确认", new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, CreateCourierTeamActivity.class);
                context.startActivity(intent);
                dialog.dismiss();
            }
        });

        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 申请加入战队
     *
     * @param context
     */
    public static void courierJoinTeamDialog(final TeamCenterZoneListActivity context, final Object teamId) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.dialog_courier_join_team_item);
        final DeleteEditText editText = dialog.findViewById(R.id.self_evaluation_et);
        //设置可获得焦点
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        //请求获得焦点
        editText.requestFocus();
        editText.setFilters(new InputFilter[]{new InputFilterExt(4)});
        getHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                editText.setFocusable(true);
                editText.setFocusableInTouchMode(true);
                editText.requestFocus();
                Android.showSoftInput(context, editText);
            }
        }, 200);
        //提交申请
        dialog.findViewById(R.id.push_apply_team_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Str.isEmpty(editText.getText())) {
                    context.showToast("请输入自我评价");
                    return;
                }
                if (editText.getText().toString().length() <= 200) {
                    context.showLoadingDialog(null);
                    AppHttp.getInstance().applyToTeam(teamId, editText.getText().toString());
                    dialog.dismiss();
                } else {
                    context.showToast("最多可输入200字");
                }
            }
        });
        dialog.show();
    }

    /**
     * 火箭侠申请加入时提示：2个月内不得退出
     *
     * @param context
     */
    public static void courierNoExitForTwoMonthsDialog(final TeamCenterZoneListActivity context, final Object teamId) {
        final AppDialog dialog = new AppDialog(context);
        TextView titleTV = (TextView) dialog.findViewById(R.id.app_dialog_title);
        titleTV.setText("温馨提示");
        titleTV.setGravity(Gravity.LEFT);
        titleTV.setTextSize(20);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.getPaint().setFakeBoldText(true);
        TextView contentTV = (TextView) dialog.findViewById(R.id.app_dialog_content);
        contentTV.setGravity(Gravity.LEFT);
        contentTV.setTextSize(16);
        contentTV.setVisibility(View.VISIBLE);
        contentTV.setTextColor(R.color.app_font_2);
        contentTV.setLineSpacing(3, 1.2f);
        contentTV.setText("申请成功后，2个月内不得退出。");
        dialog.setConfirmClickListener("申请加入", new OnClickListener() {
            @Override
            public void onClick(View view) {
                courierJoinTeamDialog(context, teamId);
                dialog.dismiss();
            }
        });

        dialog.setCancelClickListener("再想想", new OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 火箭侠申请加入时提示：重复申请
     *
     * @param context
     */
    public static void courierDuplicateClaimDialog(final TeamCenterZoneListActivity context, String teamNameStr, final Object teamId) {
        final AppDialog dialog = new AppDialog(context);
        TextView titleTV = (TextView) dialog.findViewById(R.id.app_dialog_title);
        titleTV.setText("温馨提示");
        titleTV.setGravity(Gravity.LEFT);
        titleTV.setTextSize(20);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.getPaint().setFakeBoldText(true);
        TextView contentTV = (TextView) dialog.findViewById(R.id.app_dialog_content);
        contentTV.setGravity(Gravity.LEFT);
        contentTV.setTextSize(16);
        contentTV.setVisibility(View.VISIBLE);
        contentTV.setTextColor(R.color.app_font_2);
        contentTV.setLineSpacing(3, 1.2f);
        contentTV.setText("您之前已申请" + teamNameStr + "战队，不可同时申请多个战队，是否取消" + teamNameStr + "战队的申请");
        dialog.setConfirmClickListener("申请加入", new OnClickListener() {
            @Override
            public void onClick(View view) {
                courierJoinTeamDialog(context, teamId);
                dialog.dismiss();
            }
        });

        dialog.setCancelClickListener("再想想", new OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 火箭侠申请加入时提示：战队申请时效
     *
     * @param context
     */
    public static void courierApplyForAgingDialog(final TeamCenterZoneListActivity context, final Object teamId) {
        final AppDialog dialog = new AppDialog(context);
        TextView titleTV = (TextView) dialog.findViewById(R.id.app_dialog_title);
        titleTV.setText("温馨提示");
        titleTV.setGravity(Gravity.LEFT);
        titleTV.setTextSize(20);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.getPaint().setFakeBoldText(true);
        TextView contentTV = (TextView) dialog.findViewById(R.id.app_dialog_content);
        contentTV.setGravity(Gravity.LEFT);
        contentTV.setTextSize(16);
        contentTV.setVisibility(View.VISIBLE);
        contentTV.setTextColor(R.color.app_font_2);
        contentTV.setLineSpacing(3, 1.2f);
        contentTV.setText("若战队在3天21小时后组队成功，您将自动成为战队成员，且2个月内不得推出。\n\n若组队失败，您将自动解除战队身份，可申请其他战队。");
        dialog.setConfirmClickListener("申请加入", new OnClickListener() {
            @Override
            public void onClick(View view) {
                courierJoinTeamDialog(context, teamId);
                dialog.dismiss();
            }
        });

        dialog.setCancelClickListener("再想想", new OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 战队详情
     *
     * @param context
     * @param nickName     花名
     * @param name         真是姓名
     * @param manifestoStr 战队宣言
     * @param introduceStr 战队介绍
     */
    public static void courierTeamDetailsDialog(Activity context, String headImagePath, String nickName, String name, String manifestoStr, String introduceStr) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.dialog_courier_team_details);
        //队长头像
        CircularImage mTitleImage = dialog.findViewById(R.id.title_image);
        //队长昵称
        TextView mCaptainNameTV = dialog.findViewById(R.id.captain_name_tv);
        //战队宣言
        TextView mTeamManifestoTV = dialog.findViewById(R.id.team_manifesto_tv);
        //战队简介
        TextView mTeamIntroduceTV = dialog.findViewById(R.id.team_introduce_tv);
        GlideUtil.loadImage(context, headImagePath, R.drawable.setting_head_hover_default, mTitleImage);
        if (Str.isEmpty(name)) {
            mCaptainNameTV.setText(nickName + "（）");
        } else {
            mCaptainNameTV.setText(nickName + "（" + name.substring(0, 1) + "师傅）");
        }
        mTeamManifestoTV.setText("战队宣言：" + manifestoStr);
        mTeamIntroduceTV.setText(introduceStr);
        dialog.findViewById(R.id.close).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }

    /**
     * 确认解散战队
     *
     * @param context
     */
    public static void teamDissolveDialog(final Activity context, final int teamId) {
        final AppDialog dialog = new AppDialog(context);
        TextView titleTV = (TextView) dialog.findViewById(R.id.app_dialog_title);
        titleTV.setText("重要提示");
        titleTV.setGravity(Gravity.LEFT);
        titleTV.setTextSize(20);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.getPaint().setFakeBoldText(true);
        TextView contentTV = (TextView) dialog.findViewById(R.id.app_dialog_content);
        contentTV.setGravity(Gravity.LEFT);
        contentTV.setTextSize(16);
        contentTV.setVisibility(View.VISIBLE);
        contentTV.setTextColor(R.color.app_font_2);
        contentTV.setLineSpacing(3, 1.2f);
        contentTV.setText("是否要确认要解散战队？点击确认后，您将无法撤回该操作！");
        dialog.setConfirmClickListener("确认", new OnClickListener() {
            @Override
            public void onClick(View view) {
                ((CourierTeamCenterDetailActivity) context).showLoadingDialog(null);
                AppHttp.getInstance().courierTeamCancel(teamId, 2);
                dialog.dismiss();
            }
        });

        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 确认退出该战队
     *
     * @param context
     */
    public static void teamExitDialog(final Activity context, final int teamId) {
        final AppDialog dialog = new AppDialog(context);
        TextView titleTV = (TextView) dialog.findViewById(R.id.app_dialog_title);
        titleTV.setText("重要提示");
        titleTV.setGravity(Gravity.LEFT);
        titleTV.setTextSize(20);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.getPaint().setFakeBoldText(true);
        TextView contentTV = (TextView) dialog.findViewById(R.id.app_dialog_content);
        contentTV.setGravity(Gravity.LEFT);
        contentTV.setTextSize(16);
        contentTV.setVisibility(View.VISIBLE);
        contentTV.setTextColor(R.color.app_font_2);
        contentTV.setLineSpacing(3, 1.2f);
        contentTV.setText("是否确认要退出该战队？点击确认后，您将无法撤回该操作！");
        dialog.setConfirmClickListener("确认", new OnClickListener() {
            @Override
            public void onClick(View view) {
                ((CourierTeamCenterDetailActivity) context).showLoadingDialog(null);
                AppHttp.getInstance().courierTeamCancel(teamId, 1);
                dialog.dismiss();
            }
        });

        dialog.setCancelClickListener("取消", new OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * @param context
     * @param serviceTaskBean
     * @param type            0 寄件码  1 收件码
     */
    public static void confirmSendCodeDialog(final Activity context, ServiceTaskBean serviceTaskBean, final int type) {
        final BaseDialog dialog = new BaseDialog(context, R.style.app_dialog_theme1);
        dialog.setContentView(R.layout.activity_task_send_code);
        if (type == 1) {
            ((TextView) dialog.findViewById(R.id.title_tv)).setText("请输入收件码");
        } else {
            ((TextView) dialog.findViewById(R.id.title_tv)).setText("请输入寄件码");
        }
        final CodeLinearLayout codeLinearLayout = (CodeLinearLayout) dialog.findViewById(R.id.task_sendcode_input_layout);
        ImageView cancelIV = (ImageView) dialog.findViewById(R.id.close_iv);
        TextView messageTipsTV = (TextView) dialog.findViewById(R.id.send_message_tip_tv);
        getHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                codeLinearLayout.setFocusable(true);
                codeLinearLayout.setFocusableInTouchMode(true);
                codeLinearLayout.requestFocus();
                EditText first = (EditText) codeLinearLayout.getChildAt(0);
                first.requestFocus();
                Android.showSoftInput(context, codeLinearLayout);
            }
        }, 200);
        if (serviceTaskBean != null) {
            if (type == 1) {
                messageTipsTV.setText("收件码已发送到" + serviceTaskBean.getGivePhone() + "手机上\n也可在火箭令牌中获取");
            } else {
                messageTipsTV.setText("寄件码已发送到" + serviceTaskBean.getPhone() + "手机上\n也可在火箭令牌中获取");
            }
            codeLinearLayout.setCallback(new Callback() {
                @Override
                public void execute(Object... result) {
                    String code = codeLinearLayout.getText();
                    if (code.length() == 6) {
                        Android.hideSoftInput(context);
                        if (context instanceof TaskMainDetailActivity) {
                            ((TaskStageFragment) ((TaskMainDetailActivity) context).mFragment1).setSendCode(code);
                        } else if (context instanceof SameCityTaskMainActivity) {
                            ((SameCityTaskStageFragment) ((SameCityTaskMainActivity) context).mFragment1).setSendCode(type, code);
                        }
                        dialog.dismiss();
//                        Intent intent = new Intent();
//                        intent.putExtra("code", code);
//                        setResult(Activity.RESULT_OK, intent);
//                        finish();
                    }
                }
            });
        }
        cancelIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getHandler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Android.hideSoftInput(context);
                    }
                }, 200);
                dialog.dismiss();
            }
        });
        dialog.show();
    }
}
